package com.heima.model.common.dtos;

import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.common.enums.ModelNameEnum;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description
 * @Author pure
 * @Date DATE D A T E {TIME}
 */
@Data
@Accessors(chain = true)
public class JsonResult {

    private String type; //类型层
    private Map<String, Object> data = new HashMap<>();

    public JsonResult data(String key, Object value){
        this.data.put(key, value);
        return this;
    }

    public static JsonResult ok(String type){
        JsonResult r = new JsonResult();
        r.setType(type);
        return r;
    }


    public static JsonResult error(String type){
        JsonResult r = new JsonResult();
        r.setType(type);
        return r;
    }

//    {"error":[{"code":"100","msg":"xxxxx","fun":"funname"}], "type":"controller" }
//    {"error":[{"code":"100","msg":"xxxxx","fun":"funname"}], "type":"service" }
    public static JsonResult Errorinfo(String type,Object value){
        return JsonResult.error(type).data(ModelNameEnum.ERROR_INFO.getModelName(), value);
    }

//    {"userinfo":[{"id":"1111","name":""},{"id":"1111","name":""}], "type":"service" }
//    {"userinfo":[{"id":"1111","name":""},{"id":"1111","name":""}], "type":"controller" }
    public static JsonResult Userinfo(String type,Object value){
        return JsonResult.ok(type).data(ModelNameEnum.USER_INFO.getModelName(), value);
    }










}
